<template>
	<view class="content">
		<view class="user">
			<image class="userIcon" v-if="headImgUrl" :src="headImgUrl?headImgUrl:'/static/logo.png'" />
			<span v-if="!headImgUrl" class="userIcon-default">
				<b>
					{{nickname?nickname.substring(0,1):''}}
				</b>
			</span>
			<view v-if="token" class="userInfo">
				<b class="nickName">{{ nickname }}</b>
				<span class="userName">账户：{{ username }}</span>
			</view>
			<view v-if="!token" class="loginButtonView">
				<navigator class="loginButton" hover-class="navigator-hover" url="/pages/login/index">
					登 录
				</navigator>
			</view>
		</view>
		<view class="menu-list-container" v-if="token">
			<view class="menu-list">
				<navigator class="menu-item" url="/pages/mine/user_info">
					<button class="menu-item-button">
						<span class="menu-item-button-text">个人信息</span>
					</button>
				</navigator>
			</view>
			<view class="menu-list">
				<navigator class="menu-item" url="/pages/mine/my_publish">
					<button class="menu-item-button">
						<span class="menu-item-button-text">我的发布</span>
					</button>
				</navigator>
			</view>
			<view class="menu-list">
				<button class="menu-item-button" @click="loginOut">
					<span class="menu-item-button-text">退出登录</span>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex'
	import operate from "../../common/utils/operate";
	import {
		getToken
	} from "../../common/utils/auth";
	export default {
		computed: {
			...mapGetters({
				token: 'token',
				username: 'username',
				nickname: 'nickname',
				headImgUrl: 'headImgUrl',
			}),
		},
		data() {
			return {}
		},
		onLoad() {

		},
		methods: {
			loginOut() {
				console.log('loginOut')
				this.$store.dispatch('loginOut')
				this.$websocket.closeConnect()
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #dadada;
	}

	.loginButtonView {
		width: 60%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.loginButton {
		width: 300rpx;
		height: 200rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: large;
		background-color: #ffffff;
		border: 1px solid #d2d2d2;
		border-radius: 50rpx
	}

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.user {
		width: 100%;
		display: flex;
		flex-direction: row;
		background-color: white;
	}

	.userIcon {
		height: 200rpx;
		width: 200rpx;
		margin: 50rpx auto 50rpx 5%;
	}

	.userIcon-default {
		height: 200rpx;
		width: 200rpx;
		margin: 50rpx auto 50rpx 5%;
		border-radius: 20rpx;
		background-color: #37a8a6;
		text-align: center;
		display: flex;
		flex-direction: column;
		justify-content: center;
		font-size: 60rpx;
		color: #ffffff;
	}

	.userInfo {
		width: 60%;
		height: 300rpx;
		display: flex;
		flex-direction: column;
	}

	.nickName {
		width: 100%;
		height: 50%;
		line-height: 150rpx;
	}

	.userName {
		width: 100%;
		height: 50%;
		line-height: 120rpx;
		color: #b1b1b1;
	}
</style>
